package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TeaShopEmployee;
import com.ruoyi.system.service.ITeaShopEmployeeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 茶店员工Controller
 * 
 * @author ruoyi
 * @date 2023-12-31
 */
@Controller
@RequestMapping("/system/employee")
public class TeaShopEmployeeController extends BaseController
{
    private String prefix = "system/employee";

    @Autowired
    private ITeaShopEmployeeService teaShopEmployeeService;

    @RequiresPermissions("system:employee:view")
    @GetMapping()
    public String employee()
    {
        return prefix + "/employee";
    }

    /**
     * 查询茶店员工列表
     */
    @RequiresPermissions("system:employee:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TeaShopEmployee teaShopEmployee)
    {
        startPage();
        List<TeaShopEmployee> list = teaShopEmployeeService.selectTeaShopEmployeeList(teaShopEmployee);
        return getDataTable(list);
    }

    /**
     * 导出茶店员工列表
     */
    @RequiresPermissions("system:employee:export")
    @Log(title = "茶店员工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TeaShopEmployee teaShopEmployee)
    {
        List<TeaShopEmployee> list = teaShopEmployeeService.selectTeaShopEmployeeList(teaShopEmployee);
        ExcelUtil<TeaShopEmployee> util = new ExcelUtil<TeaShopEmployee>(TeaShopEmployee.class);
        return util.exportExcel(list, "茶店员工数据");
    }

    /**
     * 新增茶店员工
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存茶店员工
     */
    @RequiresPermissions("system:employee:add")
    @Log(title = "茶店员工", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TeaShopEmployee teaShopEmployee)
    {
        return toAjax(teaShopEmployeeService.insertTeaShopEmployee(teaShopEmployee));
    }

    /**
     * 修改茶店员工
     */
    @RequiresPermissions("system:employee:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TeaShopEmployee teaShopEmployee = teaShopEmployeeService.selectTeaShopEmployeeById(id);
        mmap.put("teaShopEmployee", teaShopEmployee);
        return prefix + "/edit";
    }

    /**
     * 修改保存茶店员工
     */
    @RequiresPermissions("system:employee:edit")
    @Log(title = "茶店员工", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TeaShopEmployee teaShopEmployee)
    {
        return toAjax(teaShopEmployeeService.updateTeaShopEmployee(teaShopEmployee));
    }

    /**
     * 删除茶店员工
     */
    @RequiresPermissions("system:employee:remove")
    @Log(title = "茶店员工", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(teaShopEmployeeService.deleteTeaShopEmployeeByIds(ids));
    }
}
